package me.ywy.kotlinvideo.base

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import me.ywy.kotlinvideo.ui.activity.MainActivity
import org.jetbrains.anko.AnkoLogger
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast

/**
 * Created by ywy on 2018-10-30.
 */
abstract class BaseActivity:AppCompatActivity(),AnkoLogger {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(getLayoutId())
        initView()
        initListener()
        initData(intent)
    }

    protected open fun initData(intent: Intent){}
    /**
     * 初始化控件监听器
     * 适合adapter listener 的操作
     */
    protected open fun initListener(){}

    /**
     * 初始化页面控件
     */
    protected open fun initView(){}

    /**
     * 获取布局ID
     */
    protected abstract fun getLayoutId(): Int

    protected fun myToast(msg:String){
        runOnUiThread {
            toast(msg)
        }
    }

    protected inline fun <reified T:BaseActivity>startActivityAndFinishThis(){
        startActivity<T>()
        finish()
    }

}